//
//  BiDismountEngine.m
//  TrunkIndustryManageSystem
//
//  Created by WT_lyy on 15/4/30.
//  Copyright (c) 2015年 李璐西. All rights reserved.
//

#import "BiDismountEngine.h"

#import "BiNetEngine.h"
#import "ASIFormDataRequest.h"
#import "BiPurchaseParser.h"
#import "ASINetworkQueue.h"

#import "BiDismountParser.h"
@implementation BiDismountEngine
SINGLE_INSTANCE_IMPLEMENTION(BiDismountEngine)


/**
 *   //  获取整车拆装（完结）列表， 下拉刷新请求更多，dict为传入参数字典
 */
- (void)requestDismountCarList:(id)delegate paraDict:(NSDictionary *)dict{
    
    NSString *url = [NSString stringWithFormat:@"%@/mobile.php/CarDismountCenter/getList", SERVICE_URL];

    [_dataDic setObject:delegate forKey:[NSNumber numberWithInt:NET_GET_DISMOUNT_MOUNT_LIST]];
    
    [self createPostRequest:url paramDic:dict tag:NET_GET_DISMOUNT_MOUNT_LIST];
}



/**
 *   //  获取整车拆装（完结）审核， dict为传入参数字典
 */
- (void)requestDismountCarCheck:(id)delegate paraDict:(NSDictionary *)dict{
    NSString *url = [NSString stringWithFormat:@"%@/mobile.php/CarDismountCenter/modify", SERVICE_URL];
    
    [_dataDic setObject:delegate forKey:[NSNumber numberWithInt:NET_GET_DISMOUNT_MOUNT_CHECK]];
    
    [self createPostRequest:url paramDic:dict tag:NET_GET_DISMOUNT_MOUNT_CHECK];
    
}


- (void)requestDone:(ASIHTTPRequest *)request
{
    int tag = [[[request userInfo] objectForKey:@"t_tag"] intValue];
    
    int httpCode = [request responseStatusCode];
    
    if (200 > httpCode || 300 <= httpCode)
    {
        NSLog(@"http error --- tag = %d, http code = %d", tag, httpCode);
        assert(0);
        return;
    }
    
    switch (tag)
    {
        case NET_GET_DISMOUNT_MOUNT_LIST:
        {
            [self onGetDismountListData:request];
        }
            break;
        case NET_GET_DISMOUNT_MOUNT_CHECK:
        {
            [self onGetDismountCheckData:request];
        }
            break;
        default:
            break;
    }
    
}

- (void)onGetDismountListData:(ASIHTTPRequest *)request
{
    int httpCode = [request responseStatusCode];
    
    if (200 != httpCode)
    {
        return;
    }
    
    int tag = [[[request userInfo] objectForKey:@"t_tag"] intValue];
    
    id delegate = [_dataDic objectForKey:[NSNumber numberWithInt:tag]];
    [_dataDic removeObjectForKey:[NSNumber numberWithInt:tag]];  // 请求完后清除掉delegate
    
    if (nil != delegate && [delegate respondsToSelector:@selector(onNetEngineResponse:entity:userInfo:)])
    {
        id  entity  = [BiDismountParser  parserCarDismountListEntity:[request responseString]];
        [delegate onNetEngineResponse:tag entity:entity userInfo:nil];
    }
}

- (void)onGetDismountCheckData:(ASIHTTPRequest *)request
{
    int httpCode = [request responseStatusCode];
    
    if (200 != httpCode)
    {
        return;
    }
    
    int tag = [[[request userInfo] objectForKey:@"t_tag"] intValue];
    
    id delegate = [_dataDic objectForKey:[NSNumber numberWithInt:tag]];
    [_dataDic removeObjectForKey:[NSNumber numberWithInt:tag]];  // 请求完后清除掉delegate
    
    if (nil != delegate && [delegate respondsToSelector:@selector(onNetEngineResponse:entity:userInfo:)])
    {
        id  entity  = [BiDismountParser  parserCarDismountListEntity:[request responseString]];
        [delegate onNetEngineResponse:tag entity:entity userInfo:nil];
    }
}


@end
